package com.qf.fengmimall.handler;

import com.qf.fengmimall.ex.UserException;
import com.qf.fengmimall.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 刘欣
 * @createTime 2023/2/13 13:20
 * @description 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class ExHandler {

    @ExceptionHandler(UserException.class)
    public ResultVo exUserHandler(UserException userException) {
        log.debug("用户模块异常userException={0}", userException.getMessage());
        return ResultVo.error(userException.getMessage());
    }


    @ExceptionHandler({Exception.class})
    public ResultVo exHandler(Exception ex) {
        log.debug("系统异常exception={0}", ex.getMessage());
        return ResultVo.error(ex.getMessage());
    }
}
